package com.superMall.controller.portal;

import com.github.pagehelper.PageInfo;
import com.superMall.common.Const;
import com.superMall.common.ResponseCode;
import com.superMall.common.ServerResponse;
import com.superMall.pojo.User;
import com.superMall.service.IProductService;
import com.superMall.vo.ProductDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by guanwei on 2017/11/20.
 */

@Controller
@RequestMapping("/product/")
public class ProductController {

    @Autowired
    private IProductService iProductService;


    /**
     * 查看商品详情
     * @param productId
     * @return
     */
    @RequestMapping(value = "detail.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<ProductDetailVO> getDetail(Integer productId){
            return iProductService.getProductDetail(productId);
    }


    /**
     * 根据关键字和categoryId查找商品
     * @param pageNum
     * @param pageSize
     * @param orderBy
     * @param categoryId
     * @param keyword
     * @return
     */
    @RequestMapping(value = "list.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<PageInfo> list( @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                         @RequestParam(value ="orderBy",defaultValue = "")String orderBy,
                                          Integer categoryId, String keyword){

        return iProductService.getProductByKeywordCategory(pageNum,pageSize,orderBy,categoryId,keyword);
    }

}
